package course;

import java.sql.ResultSet;
import java.util.*;

import util.DBConnection;

public class MyCourse extends Course{
	DBConnection DB;
	private String s_id;;
	//private Date add_time; 
	public MyCourse(){
		DB=new DBConnection();
		DB.connect();
	}
	public void setSid(String s_id){
		this.s_id=s_id;
	}
	public String getSid(){
		return s_id;
	}
	/*public void setAddTime(Date add_time){
		this.add_time=add_time;
	}
	public Date getAddTime(){
		return add_time;
	}*/
	public ArrayList<MyCourse> findBySid(String s_id){
		ArrayList<MyCourse> courses=new ArrayList<MyCourse>();
		String sql="select * from addcourse ac,course c,teacher t where s_id ='"+s_id+"' and ac.c_id=c.c_id and c.t_id=t.t_id";
		ResultSet rs=DB.executeQuery(sql);
		try{
			while(rs.next()){
				MyCourse ac=new MyCourse();
				ac.setCid(rs.getString("c_id"));
				ac.setTid(rs.getString("t_id"));
				ac.setCname(rs.getString("cname"));
				ac.setTeacher(rs.getString("name"));
				ac.setCategory(rs.getString("category"));
				ac.setTeachOutline(rs.getString("teach_outline"));
				ac.setTeachPlan(rs.getString("teach_plan"));
				ac.setSid(rs.getString("s_id"));
				//ac.setAddTime(rs.getDate("add_time"));
				courses.add(ac);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			DB.close();
		}
		return courses;
	}
	public boolean add(String sid,String cid){
		//Date now=new Date();
		String sql="insert into addcourse values('"+sid+"','"+cid+"',null)";
		return DB.executeUpdate(sql);
	}
	public boolean delete(String s_id,String c_id){
		String sql="delete  from addcourse where s_id='"+s_id+"' and c_id='"+c_id+"'";
		return DB.executeUpdate(sql);
	}
}
